package com.gis.aoitest.source;

import com.gis.aoitest.beans.SensorReading;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;
import java.util.List;

/**
 * @author LnnuUser
 * @create 2021-09-06-下午7:53
 * 从集合获取数据流，下面创建两个流，一个味pojo流，一个通过forElements创建
 */
public class SourceTest01_Collection {

    public static void main(String[] args) throws Exception {

        //创建执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        //从集合中读取数据
        List<SensorReading> dataStream = Arrays.asList(
                new SensorReading("sensor_1", 1547718291L, 15.4),
                new SensorReading("sensor_2", 1547718292L, 15.3),
                new SensorReading("sensor_3", 1547718293L, 15.5)
        );

        DataStream<SensorReading> dataStreamSource = env.fromCollection(dataStream);

        DataStreamSource<Integer> integerDataStream = env.fromElements(1, 2, 3, 4, 5, 6);

        //打印输出
        dataStreamSource.print("data");
        integerDataStream.print("int");

        //执行
        env.execute("collection");
    }
}
